# _*_ coding : utf-8 _*_
# @Time : 2023/3/15 0015 16:59
# @Author : 菜鸟王小二
# @File : 14_urllib_handler处理器的使用
# @Project : python爬虫

import urllib.request

url = 'http://www.baidu.com'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63'
}

request = urllib.request.Request(url=url,headers=headers)

# 创建handler对象
handler = urllib.request.HTTPHandler()
# 创建opener对象
opener = urllib.request.build_opener(handler)
# 调用open方法
response = opener.open(request)

content = response.read().decode('utf-8')

print(content)
